package com.purang.web.converter;

import com.purang.web.entity.dto.UserDto;
import com.purang.web.entity.vo.UserVo;
import org.apache.commons.lang3.StringUtils;
import org.mapstruct.Mapper;
import org.mapstruct.Mapping;
import org.mapstruct.factory.Mappers;

/**
 * DTO转换器
 *
 * @author Chunyan Li
 * @version 1.0-RELEASE
 * @since 1.0-RELEASE
 */
@Mapper
public interface DtoConverter {

    DtoConverter INSTANCE = Mappers.getMapper(DtoConverter.class);

    @Mapping(expression = "java(genderParse(userVo.getGender()))", target = "gender")
    UserDto convert(UserVo userVo);

    default Integer genderParse(String gender) {
        if (StringUtils.equals("男", gender)) {
            return 1;
        } else if (StringUtils.equals("女", gender)) {
            return 0;
        } else {
            return null;
        }
    }
}
